//
//  NYContactCollectionCell.m
//  NiuWaJiaoYu
//
//  Created by MinLison on 2018/1/6.
//  Copyright © 2018年 niuwaketang. All rights reserved.
//

#import "NYContactCollectionCell.h"
#import "NYContactItemModel.h"

@interface NYContactCollectionCell ()

@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIImageView *qrImageView;

@property (nonatomic, strong) NYContactItemModel *itemModel;
@end

@implementation NYContactCollectionCell

+ (CGSize)sizeForObject:(id)object identifier:(NSString *)identifier atIndexPath:(NSIndexPath *)indexPath collectionView:(UICollectionView *)collectionView {
    
    return CGSizeMake(SCREEN_WIDTH/2, (SCREEN_WIDTH - 105)/2.f + 63);
}
- (BOOL)shouldUpdateCellWithObject:(NYContactItemModel *)object {
    
    if (![object isKindOfClass:[NYContactItemModel class]]) {
        return false;
    }

    self.itemModel = object;
    return true;
}

- (void)setupView {
    [super setupView];
    
    [self.contentView addSubview:self.qrImageView];
    [self.contentView addSubview:self.nameLabel];

    [self.nameLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(self.contentView);
        make.height.mas_equalTo(15);
    }];
}

- (void)setItemModel:(NYContactItemModel *)itemModel{
    _itemModel = itemModel;
    [self updateContent];
}
- (void)updateContent {
    
    [self.qrImageView sd_setImageWithURL:[NSURL URLWithString:_itemModel.picurl] placeholderImage:[UIImage imageWithColor:UIColorMakeWithHex(@"#E5E5E5")]];
    self.nameLabel.text = self.itemModel.name;
}

- (UIImageView *)qrImageView {
    if (!_qrImageView) {
        _qrImageView = [[UIImageView alloc] initWithFrame:CGRectMake(35, 35, (SCREEN_WIDTH - 105)/2.f, (SCREEN_WIDTH - 105)/2.f)];
        _qrImageView.image = [UIImage imageWithColor:UIColorMakeWithHex(@"#E5E5E5")];
    }
    return _qrImageView;
}
- (UILabel *)nameLabel {
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc] initWithFrame:CGRectZero];
        _nameLabel.textColor = UIColorMakeWithHex(@"#333333");
        _nameLabel.textAlignment = NSTextAlignmentCenter;
        _nameLabel.font = UIFontMake(14);
    }
    return _nameLabel;
}

@end
